﻿
dynamic class Snows extends MovieClip
{
	private var speed:Number = 5;
	private var leftwin:Number = -2;
	private var rightwin:Number = 5;
	private var minScale:Number = 10;
	private var maxScale:Number = 100;
	
	private var nowSpeed:Number = 0;
	private var nowScale:Number = 100;
	private var nowWin:Number = 0;
	public function Snows()
	{
		this._visible = false;
	}
	public function start(_speed:Number,_leftwin:Number,_rightwin:Number,_minScale:Number,_maxScale:Number)
	{
		if (_speed != undefined)
		{
			this.speed = _speed;
		}
		
		if (_leftwin != undefined)
		{
			this.leftwin = _leftwin;
		}
		
		if (_rightwin != undefined)
		{
			this.rightwin = _rightwin;
		}
		
		if (_minScale != undefined)
		{
			this.minScale = _minScale;
		}
		
		if (_maxScale != undefined)
		{
			this.maxScale = _maxScale;
		}
		this.setValues();
		this.onEnterFrame = this.enterFrameFun;
	}
	public function pause()
	{
		if (this.onEnterFrame == null)
		{
			this.onEnterFrame = this.enterFrameFun;
		}else
		{
			this.onEnterFrame = null;
		}
	}
	public function stop()
	{
		this.onEnterFrame = null;
		this._visible = false;
	}
	private function enterFrameFun()
	{
		var y:Number = (this._y + this.nowSpeed) % Stage.height;
		
		//trace(y+"|"+this._y+"||||"+this._parent._height);
		if (y < this._y || this._x<0 || this._x>Stage.width)
		{
			this.setValues();
		}
		this.moveSelf();
	}
	private function moveSelf()
	{
		this._y += this.nowSpeed;
		this._x += this.nowWin;
		this._xscale = this._yscale = this.nowScale;
	}
	private function setValues()
	{
		var scalebl:Number = Math.random();
		nowScale = minScale + (maxScale - minScale) * scalebl;
		nowSpeed = scalebl * speed;
		this.nowWin = Math.pow(scalebl,0.2) * (Math.random() * (this.rightwin - this.leftwin) + this.leftwin);
		this._x = Math.random() * this._parent._width;
		this._y = 0;
		this._visible = true;
	}
}